<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns" :dataSource="dataSource"
        :pagination="ipagination" :loading="loading" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap" @change="handleTableChange">

        <template slot="piclot" slot-scope="text, record">
          
          <viewer :images="record.piecesSrc.split(',')" v-if="record.piecesType == 1">
            <a v-for="(src,index) in record.piecesSrc.split(',')" >
                <!-- <img :src="src" width="150" height="140" v-if="index == 0"/> -->
                <img :src="src" width="150" height="140" v-if="index == 0"/>
                <img :src="src" width="150" height="140" v-if="index > 0" hidden/>
            </a>
          </viewer>

          <a v-else-if="record.piecesType == 2" :href="record.piecesSrc" target="_blank">
            <img :src="record.piecesSrc +'?x-oss-process=video/snapshot,t_7000,f_jpg,w_1000,h_800,m_fast' " width="200"
              height="140" />
          </a>
        </template>


        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

       <span slot="action" slot-scope="text, record">
            <!-- <a-switch :default-checked="false" @change='onChange($event,record)' v-if="record.audit== 3" />
            <a-switch :default-checked="true" @change='onChange($event,record)' v-if="record.audit== 2" />
            <a-switch :default-checked="false" @change='onChange($event,record)' v-if="record.audit== 1" /> -->
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多
              <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="getInfo(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <community-naxin-modal ref="modalForm" @ok="modalFormOk"></community-naxin-modal>

    <a-modal v-model="visible" title="详情" @ok="handleOk">
         <p>社团ID: &nbsp; {{info.clubId}}</p>
         <p>社团名称: &nbsp; {{info.clubName}}</p>
         <p>标题: &nbsp; {{info.title}}</p>
         <p>点赞数量: &nbsp; {{info.likeNum}}</p>
         <p v-if="this.info.piecesType == '1'">
             作品展示: &nbsp; <img :src="info.piecesSrc" width="100%" height="100%"></img> 
           <br />
         </p>
         <p v-if="this.info.piecesType == '1'">作品类型: &nbsp; 图片</p>
         
         <p v-if="info.piecesType =='2'">
           作品展示
           <a  :href="info.piecesSrc" target="_blank">
             <img :src="info.piecesSrc +'?x-oss-process=video/snapshot,t_7000,f_jpg,w_1000,h_800,m_fast' " width="100%"
               height="100%" />
           </a>
         </p >
           <p v-if="info.piecesType == '2'">作品类型: &nbsp; 视频</p>
           
         <p>简介: &nbsp; {{info.brief}}</p>
    </a-modal>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import {
    mixinDevice
  } from '@/utils/mixin'
  import {
    JeecgListMixin
  } from '@/mixins/JeecgListMixin'
  import CommunityNaxinModal from './modules/CommunityNaxinModal'


  export default {
    name: "CommunityNaxinList",
    mixins: [JeecgListMixin, mixinDevice],
    components: {
      CommunityNaxinModal
    },
    data() {
      return {
        info: {},
        visible: false,
        description: '社团纳新表管理页面',
        // 表头
        columns: [{
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function(t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '社团ID',
            align: "center",
            dataIndex: 'clubId',
            width: 160
          },
          {
            title: '社团名称',
            align: "center",
            dataIndex: 'clubName'
          },
          {
            title: '标题',
            align: "center",
            dataIndex: 'title',
            ellipsis: true
          },
          {
            title: '点赞数量',
            align: "center",
            dataIndex: 'likeNum'
          },
          {
            title: '作品',
            align: "center",
            width: 240,
            dataIndex: 'piecesSrc',
            scopedSlots: {
              customRender: 'piclot'
            }
          },
          {
            title: '作品类型',
            align: "center",
            dataIndex: 'piecesType_dictText'
          },
          {
            title: '简介',
            align: "center",
            width: 147,
            dataIndex: 'brief',
            ellipsis: true,
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            fixed: "right",
            width: 147,
            scopedSlots: {
              customRender: 'action'
            }
          }
        ],
        url: {
          list: "/communityNaxin/communityNaxin/list",
          delete: "/communityNaxin/communityNaxin/delete",
          deleteBatch: "/communityNaxin/communityNaxin/deleteBatch",
          exportXlsUrl: "/communityNaxin/communityNaxin/exportXls",
          importExcelUrl: "communityNaxin/communityNaxin/importExcel",

        },
        dictOptions: {},
      }
    },
    created() {},
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig() {},
      pass(id) {
        this.axios.get("/communityNaxin/communityNaxin/audit", {
          params: {
            id: id,
            audit: '2'
          }
        }).then((res) => {
          this.loadData();
        })
      },
      npass(id) {
        this.axios.get("/communityNaxin/communityNaxin/audit", {
          params: {
            id: id,
            audit: '3'
          }
        }).then((res) => {
          this.loadData();
        })
      },
      getInfo(record) {
        this.info = {};
        this.axios.get("/communityNaxin/communityNaxin/getInfo",{params:{id:record.id}}).then((res) => {
          this.info = res.result;
        })
        this.visible = true;
      },
      handleOk(e) {
        console.log(e);
        this.info = {};
        this.visible = false;
      },
      onChange(event,record){
          if(event){
              record.audit = '2';
          }else{
            record.audit = '3';
          }
          this.axios.get("/communityNaxin/communityNaxin/audit", {
            params: {
              id: record.id,
              audit: record.audit
            }
          }).then((res) => {
            this.loadData();
          })
          
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
